<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <el-row :gutter="20">
          <el-col :span="4">
            <img src="../assets/logo.png" class="logo" />
          </el-col>
          <el-col :span="16"> <h2>后台管理系统</h2></el-col>
          <el-col :span="4"><el-button link class="quit-login" @click="logOut">退出登录</el-button></el-col>
        </el-row></el-header
      >
      <el-container>
        <el-aside width="200px">
          <el-menu
            active-text-color="#ffd04b"
            background-color="#545c64"
            class="el-menu-vertical-demo"
            default-active="2"
            text-color="#fff"
            router
          >
            <!-- router 开始路由模式，若不开启路由模式，点击后不会跳转页面 -->
            <el-menu-item
              :index="item.path"
              v-for="item in leftMenu"
              :key="item.path"
            >
              <!-- <el-icon><icon-menu /></el-icon> -->
              <span>{{ item.meta.title }}</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 展示的视图 -->
          <RouterView />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { useRouter } from "vue-router";

export default defineComponent({
  name: "HomeView",
  components: {},
  setup() {
    const router = useRouter();
    // console.log(router.getRoutes())
    // 通过元信息过滤出要在左侧栏展示的路由
    const leftMenu = router.getRoutes().filter((v) => v.meta.isShow);
    // console.log(list)

    // funcation
    const logOut = ()=>{
      localStorage.removeItem('token')
      router.push('/login')
    }
    return { leftMenu, logOut };
  },
});
</script>

<style lang="scss" scoped>
.el-header {
  height: 80px;
  background-color: #666;
  .logo {
    width: 80px;
    height: 80px;
  }
  h2,
  .quit-login {
    text-align: center;
    height: 80px;
    line-height: 80px;
    color: #fff;
  }
}

.el-aside {
  // 通过页面定位css， 计算需要的高度
  .el-menu {
    height: calc(100vh - 80px);
  }
}
</style>
